/*
 * Copyright 2011 Romain Gilles
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jvdb;

import org.slf4j.Logger;

import java.lang.reflect.Method;
import java.sql.CallableStatement;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: romain.gilles
 * Date: 1/14/11
 * Time: 2:53 PM
 * To change this template use File | Settings | File Templates.
 */
class PreparedStatementHandler extends StatementHandler {
    static final Set<Method> parametersMethods = createMethodsSet();

    static private Set<Method> createMethodsSet() {
        Set<Method> result = new HashSet<Method>();
        Method[] methods = CallableStatement.class.getMethods();
        for (Method method : methods) {
            if (method.getName().startsWith("set")) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length > 1
                        && (parameterTypes[0].equals(Integer.TYPE) || parameterTypes[0].equals(String.class))
                        ) {
                    result.add(method);
                }
            }
        }
        return result;
    }

    public PreparedStatementHandler(Logger logger, Object jdbcObj) {
        super(logger, jdbcObj);
    }
}
